<template>
    <el-dialog v-model="dialogFormVisible" :title="title" @close="closeDialog" style="width:700px;height: 200px;">
        <div style=" height: 50px;">
            <el-select v-model="year" placeholder="请选择删除年限" style="width: 240px">
                <el-option v-for="item in yearData" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
        </div>

        <template #footer>
            <span class="dialog-footer">
                <el-button @click="cancel()">取消</el-button>
                <el-button v-show="delLook" type="primary" @click="save()" :disabled="delFlag"><span v-if="delFlag">{{
        timeStr }}s</span> 确认删除</el-button>
                <el-button v-show="!delLook" type="primary" @click="saveHandle()">删除</el-button>
            </span>
        </template>
    </el-dialog>
</template>

<script>
import { ref } from "vue";
import { httpService } from "@/utils/httpService";
import { formatTime } from "@/utils/dateFormat";
import { ElMessage, ElForm } from "element-plus";
import { vxRule } from "@/utils/validator";
import zhCn from "element-plus/lib/locale/lang/zh-cn";
export default {
    name: "AddBaseAddress",
    components: { ElForm, ElMessage },
    data() {
        return {
            dialogFormVisible: ref(false),
            formLabelWidth: "120px",
            title: "",
            personnelType: "",
            id: '',
            yearData: [],
            year: '',
            canClick: false,
            timeStr: 15,
            delFlag: false,
            delLook: false,
        };
    },
    setup() {
        return {
            locale: zhCn,
        };
    },
    mounted() {
        this.getYear()
    },
    methods: {
        closeDialog() {
            this.clear();
        },
        cancel() {
            this.dialogFormVisible = false;
            this.clear();
        },
        getYear() {
            const currentYear = new Date().getFullYear();
            for (let i = 0; i < 10; i++) {
                this.yearData.push({ "label": currentYear - i, "value": currentYear - i });
            }
        },


        clear() {
            this.dialogFormVisible = false;
            //清空form
            this.id = ""
            this.delFlag = true
            this.delLook = false
            this.year = ""
        },
        saveHandle() {
            this.delLook = true
            this.delFlag = true
            let timer = setInterval(() => {
                if (this.timeStr == 0) {
                    clearInterval(timer)
                    this.timeStr = 15
                    this.delFlag = false
                } else {
                    this.timeStr -= 1
                }
            }, 1000)
        },
        save() {
            httpService("/javaApi/faSubList/deleteByYear", "year=" + this.year, "post").then(
                (data) => {
                    this.dialogFormVisible = false
                    this.delFlag = true
                    this.delLook = false
                    if (data.code == 200) {
                        ElMessage.success("删除成功");
                        this.$parent.getFaProjectList();
                    } else {
                        ElMessage.error("删除失败！");
                    }
                }
            );
        },

    },
};
</script>
<style>
.el-dialog__header {
    padding: var(--el-dialog-padding-primary);
    padding-bottom: 10px;
    border-bottom: 1px solid #dedede;
    margin-bottom: 15px;
}
</style>